#ifndef VIDEO_FRAME_H
#define VIDEO_FRAME_H

#include <cstdint>
#include <chrono>

// 定义帧处理的各个阶段
enum class FrameStage {
    CAPTURE,    // 采集
    ENCODE,     // 编码
    SEND,       // 发送
    RECEIVE,    // 接收
    DECODE,     // 解码
    RENDER      // 渲染
};

// 视频帧数据结构
class VideoFrame {
private:
    uint64_t frame_id_;                  // 帧ID
    size_t frame_size_;                  // 帧大小（字节）
    std::chrono::system_clock::time_point capture_time_;   // 采集时间戳
    std::chrono::system_clock::time_point encode_time_;    // 编码完成时间戳
    std::chrono::system_clock::time_point send_time_;      // 发送时间戳
    std::chrono::system_clock::time_point receive_time_;   // 接收时间戳
    std::chrono::system_clock::time_point decode_time_;    // 解码完成时间戳
    std::chrono::system_clock::time_point render_time_;    // 渲染完成时间戳

public:
    VideoFrame(uint64_t frame_id, size_t frame_size)
        : frame_id_(frame_id), frame_size_(frame_size) {}

    // 获取帧ID
    uint64_t getFrameId() const { return frame_id_; }
    
    // 获取帧大小
    size_t getFrameSize() const { return frame_size_; }
    
    // 设置各阶段时间戳
    void setCaptureTime(const std::chrono::system_clock::time_point& time) { capture_time_ = time; }
    void setEncodeTime(const std::chrono::system_clock::time_point& time) { encode_time_ = time; }
    void setSendTime(const std::chrono::system_clock::time_point& time) { send_time_ = time; }
    void setReceiveTime(const std::chrono::system_clock::time_point& time) { receive_time_ = time; }
    void setDecodeTime(const std::chrono::system_clock::time_point& time) { decode_time_ = time; }
    void setRenderTime(const std::chrono::system_clock::time_point& time) { render_time_ = time; }
    
    // 获取各阶段时间戳
    std::chrono::system_clock::time_point getCaptureTime() const { return capture_time_; }
    std::chrono::system_clock::time_point getEncodeTime() const { return encode_time_; }
    std::chrono::system_clock::time_point getSendTime() const { return send_time_; }
    std::chrono::system_clock::time_point getReceiveTime() const { return receive_time_; }
    std::chrono::system_clock::time_point getDecodeTime() const { return decode_time_; }
    std::chrono::system_clock::time_point getRenderTime() const { return render_time_; }
    
    // 计算各阶段处理延迟（毫秒）
    double getCaptureToEncodeLatency() const;
    double getEncodeToSendLatency() const;
    double getSendToReceiveLatency() const;
    double getReceiveToDecodeLatency() const;
    double getDecodeToRenderLatency() const;
    double getEndToEndLatency() const;
};

#endif // VIDEO_FRAME_H
